/*
 *  Copyright 2019-2020 Zheng Jie
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
package qs.crm.modules.quartz.task;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import qs.crm.modules.client.cstCustomer.service.CstCustomerService;
import qs.crm.modules.client.cstLost.domain.CstLost;
import qs.crm.modules.client.cstLost.service.CstLostService;

import java.sql.Timestamp;
import java.util.List;
import java.util.Map;

/**
 * 测试用
 * @author Zheng Jie
 * @date 2019-01-08
 */
@Slf4j
@Service
public class TestTask {
    @Autowired
    public CstCustomerService cstCustomerService;
    @Autowired
    public CstLostService cstLostService;

    public void run(){
        log.info("run 执行成功");
    }

    public void run1(String str){
        log.info("run1 执行成功，参数为： {}" + str);
    }

    public void run2(){
        log.info("run2 执行成功");
    }

    public void run3(){
//        log.info("run3 执行成功");
        List<Map<String,Object>> list =  cstCustomerService.Loss();
        for (Map<String,Object> cstCustomer : list) {
            char lstStatus = (char)cstCustomer.get("cust_status");
            if(lstStatus=='1'){
                CstLost cstLost = new CstLost();

                String str=String.valueOf(cstCustomer.get("Cust_no"));
                Long CustNo=Long.valueOf(str);
                cstLost.setLstCustNo(CustNo);

                cstLost.setLstCustName((String) cstCustomer.get("Cust_name"));

                String str1=String.valueOf(cstCustomer.get("Cust_manager_id"));
                Long Customer=Long.valueOf(str1);
                cstLost.setLstCustManagerId(Customer);
                cstLost.setLstCustManagerName((String) cstCustomer.get("Cust_manager_name"));

                cstLost.setLstLastOrderDate((Timestamp) cstCustomer.get("odr_date"));

                cstLost.setLstStatus("4");
                //新增客户流失警告
                cstLostService.create(cstLost);
                //修改客户状态
                cstCustomerService.liushi();
            }
        }
    }
}
